﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using SistemaAcademicoBO.Entities;

namespace SistemaAcademicoBLL.Util
{
    public class UsefullStuffs
    {

        #region TRANSFERS
        public static void TransferListItem(ref ListBox origem, ref ListBox destino)
        {
            if (origem.SelectedIndex >= 0)
            {
                destino.Items.Add(origem.SelectedItem);
                origem.Items.Remove(origem.SelectedItem);
            }
        }

        public static void TransferListItemDegreeCourse(ref ListBox origem, ref ListBox destino, int professorId)
        {
            if (origem.SelectedIndex >= 0)
            {
                ApplicationFacade facade = new ApplicationFacade();
                Professor professor = facade.GetProfessor(professorId);
                destino.Items.Add(new ListItem(origem.SelectedItem.Text + "(" + professor.Nome + ")", origem.SelectedValue + " - " + professorId.ToString()));
                origem.Items.Remove(origem.SelectedItem);
            }
        }

        public static void RemoveListItemDegreeCourse(ref ListBox origem, ref ListBox destino)
        {
            if (origem.SelectedIndex >= 0)
            {
                ApplicationFacade facade = new ApplicationFacade();
                string[] values = origem.SelectedValue.Split('-');
                Subject subject = facade.GetSubject(Convert.ToInt32(values[0].Trim()));

                destino.Items.Add(new ListItem(subject.SubjectName, values[0].Trim()));
                origem.Items.Remove(origem.SelectedItem);
            }
        }
        #endregion

        #region LOAD PROFESSORS
        public static DropDownList LoadProfessors(DropDownList ddl)
        {
            ddl.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<Professor> allProfessors = facade.GetAllProfessors();
            foreach (Professor professor in allProfessors)
            {
                ddl.Items.Add(new ListItem(professor.Nome, professor.ProfessorId.ToString()));
            }

            return ddl;
        }

        public static ListBox LoadProfessors(ListBox lst)
        {
            lst.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<Professor> allProfessors = facade.GetAllProfessors();
            foreach (Professor professor in allProfessors)
            {
                lst.Items.Add(new ListItem(professor.Nome, professor.ProfessorId.ToString()));
            }

            return lst;
        }
        #endregion

        #region LOAD PROFESSORSSUBJECT
        public static DropDownList LoadProfessorSubjectByProfessorId(DropDownList ddl, int professorId)
        {
            ddl.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<ProfessorSubject> allProfessorsSubject = facade.GetAllProfessorsSubjects();
            foreach (ProfessorSubject professorSubject in allProfessorsSubject)
            {
                if (professorSubject.ProfessorId == professorId)
                {
                    Professor professor = facade.GetProfessor(professorSubject.ProfessorId);
                    ddl.Items.Add(new ListItem(professor.Nome, professor.ProfessorId.ToString()));
                }
            }

            return ddl;
        }

        public static DropDownList LoadProfessorSubjectBySubjectId(DropDownList ddl, int subjectId)
        {
            ddl.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<ProfessorSubject> allProfessorsSubject = facade.GetAllProfessorsSubjects();
            foreach (ProfessorSubject professorSubject in allProfessorsSubject)
            {
                if (professorSubject.SubjectId == subjectId)
                {
                    Professor professor = facade.GetProfessor(professorSubject.ProfessorId);
                    ddl.Items.Add(new ListItem(professor.Nome, professor.ProfessorId.ToString()));
                }
            }
            return ddl;
        }

        public static DropDownList LoadProfessorSubjectBySubjectId(DropDownList ddl, int subjectId, bool TrueForSubjectNameAndValue)
        {
            ddl.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<ProfessorSubject> allProfessorsSubject = facade.GetAllProfessorsSubjects();
            foreach (ProfessorSubject professorSubject in allProfessorsSubject)
            {
                if (professorSubject.SubjectId == subjectId)
                {
                    Subject subject = facade.GetSubject(professorSubject.SubjectId);
                    ddl.Items.Add(new ListItem(subject.SubjectName, subject.SubjectId.ToString()));
                }
            }
            return ddl;
        }

        public static ListBox LoadProfessorSubjectByProfessorId(ListBox lst, int professorId)
        {
            lst.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<ProfessorSubject> allProfessorsSubject = facade.GetAllProfessorsSubjects();
            foreach (ProfessorSubject professorSubject in allProfessorsSubject)
            {
                if (professorSubject.ProfessorId == professorId)
                {
                    Professor professor = facade.GetProfessor(professorSubject.ProfessorId);
                    lst.Items.Add(new ListItem(professor.Nome, professor.ProfessorId.ToString()));
                }
            }

            return lst;
        }

        public static ListBox LoadProfessorSubjectBySubjectId(ListBox lst, int subjectId)
        {
            lst.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<ProfessorSubject> allProfessorsSubject = facade.GetAllProfessorsSubjects();
            foreach (ProfessorSubject professorSubject in allProfessorsSubject)
            {
                if (professorSubject.SubjectId == subjectId)
                {
                    Professor professor = facade.GetProfessor(professorSubject.ProfessorId);
                    lst.Items.Add(new ListItem(professor.Nome, professor.ProfessorId.ToString()));
                }
            }
            return lst;
        }

        public static ListBox LoadProfessorSubjectBySubjectId(ListBox lst, int subjectId, bool TrueForSubjectNameAndValue)
        {
            lst.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<ProfessorSubject> allProfessorsSubject = facade.GetAllProfessorsSubjects();
            foreach (ProfessorSubject professorSubject in allProfessorsSubject)
            {
                if (professorSubject.SubjectId == subjectId)
                {
                    Subject subject = facade.GetSubject(professorSubject.SubjectId);
                    lst.Items.Add(new ListItem(subject.SubjectName, subject.SubjectId.ToString()));
                }
            }
            return lst;
        }
        #endregion

        #region LOAD SUBJECTS
        public static DropDownList LoadSubjects(DropDownList ddl)
        {
            ddl.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<Subject> allSubjects = facade.GetAllSubjects();
            foreach (Subject subject in allSubjects)
            {
                ddl.Items.Add(new ListItem(subject.SubjectName, subject.SubjectId.ToString()));
            }
            return ddl;
        }

        public static ListBox LoadSubjects(ListBox lst)
        {
            lst.Items.Clear();
            ApplicationFacade facade = new ApplicationFacade();
            List<Subject> allSubjects = facade.GetAllSubjects();
            foreach (Subject subject in allSubjects)
            {
                lst.Items.Add(new ListItem(subject.SubjectName, subject.SubjectId.ToString()));
            }

            return lst;
        }
        #endregion

        #region LOAD SUBJECT IN DEGREE COURSE
        public static DropDownList LoadAllSubjectsInDegreeCourseByDegreeCourse(DropDownList ddl, int degreeCourseId)
        {
            ApplicationFacade facade = new ApplicationFacade();
            List<SubjectInDegreeCourse> allSubjectsInDegreeCourse = facade.GetAllSubjectInDegreeCourses();
            foreach (SubjectInDegreeCourse subjectInDegreeCourse in allSubjectsInDegreeCourse)
            {
                if (subjectInDegreeCourse.DegreeCourseId == degreeCourseId)
                {
                    Professor professor = facade.GetProfessor(subjectInDegreeCourse.ProfessorId);
                    Subject subject = facade.GetSubject(subjectInDegreeCourse.SubjectId);
                    ddl.Items.Add(new ListItem(subject.SubjectName + "(" + professor.Nome + ")", subjectInDegreeCourse.SubjectInDegreeCourseId.ToString()));
                }
            }
            return ddl;
        }

        public static ListBox LoadAllSubjectsInDegreeCourseByDegreeCourse(ListBox lst, int degreeCourseId)
        {
            ApplicationFacade facade = new ApplicationFacade();
            List<SubjectInDegreeCourse> allSubjectsInDegreeCourse = facade.GetAllSubjectInDegreeCourses();
            foreach (SubjectInDegreeCourse subjectInDegreeCourse in allSubjectsInDegreeCourse)
            {
                if (subjectInDegreeCourse.DegreeCourseId == degreeCourseId)
                {
                    Professor professor = facade.GetProfessor(subjectInDegreeCourse.ProfessorId);
                    Subject subject = facade.GetSubject(subjectInDegreeCourse.SubjectId);
                    lst.Items.Add(new ListItem(subject.SubjectName + "(" + professor.Nome + ")", subjectInDegreeCourse.SubjectInDegreeCourseId.ToString()));
                }
            }
            return lst;
        }
        #endregion

        #region LOAD DEGREE COURSE
        public static DropDownList LoadAllDegreeCourses(DropDownList ddl)
        {
            ApplicationFacade facade = new ApplicationFacade();
            List<DegreeCourse> degreeCourseList = facade.GetAllDegreeCourses();
            foreach (DegreeCourse degreeCourse in degreeCourseList)
            {
                ddl.Items.Add(new ListItem(degreeCourse.Nome, degreeCourse.DegreeCourseId.ToString()));
            }

            return ddl;
        }
        #endregion




    }
}
